#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import json

with open('../output/SMS_3_output_chunjinggang.json', 'r') as f:
    chujinggang = json.load(f)

with open('../output/SMS_3_output.json', 'r') as f:
    sms3 = json.load(f)

runoffSim_cjg = chujinggang['runoffSim']
timeSeries_sms3 = sms3['timeSeries']

# 找出第一个不匹配的 RunoffSim
for i in range(len(runoffSim_cjg)):
    diff = abs(runoffSim_cjg[i] - timeSeries_sms3[i]['RunoffSim'])
    if diff >= 1e-6:
        print(f'第一个 RunoffSim 不匹配在索引 {i}:')
        print(f'  时间: {timeSeries_sms3[i]["time"]}')
        print(f'  初境港: {runoffSim_cjg[i]:.15f}')
        print(f'  SMS_3:  {timeSeries_sms3[i]["RunoffSim"]:.15f}')
        print(f'  差值:   {diff:.15f}')
        print()
        
        # 显示前后时段对比
        if i > 0:
            print(f'前一个时段 (索引 {i-1}):')
            print(f'  初境港 RunoffSim: {runoffSim_cjg[i-1]:.15f}')
            print(f'  SMS_3 RunoffSim:  {timeSeries_sms3[i-1]["RunoffSim"]:.15f}')
            print()
        
        # 显示更多信息
        print(f'当前时段 (索引 {i}) 的其他值:')
        print(f'  降雨: {timeSeries_sms3[i]["rain"]}')
        print(f'  初境港 RS: {chujinggang["rSim"][0][i]:.15f}')
        print(f'  SMS_3 RS:  {timeSeries_sms3[i]["RS"]:.15f}')
        print(f'  初境港 RI: {chujinggang["rSim"][1][i]:.15f}')
        print(f'  SMS_3 RI:  {timeSeries_sms3[i]["RI"]:.15f}')
        print(f'  初境港 RG: {chujinggang["rSim"][2][i]:.15f}')
        print(f'  SMS_3 RG:  {timeSeries_sms3[i]["RG"]:.15f}')
        print()
        print(f'  初境港 WU[{i}]: {chujinggang["newStatus"]["WUP"][i]}')
        print(f'  SMS_3 WU[{i}]:  {timeSeries_sms3[i]["WU"]}')
        print(f'  初境港 S[{i}]: {chujinggang["newStatus"]["SP"][i]}')
        print(f'  SMS_3 S[{i}]:  {timeSeries_sms3[i]["S"]}')
        break
else:
    print('所有 RunoffSim 值都匹配 (差值 < 1e-6)')

